<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dv extends CI_Controller {

     public function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("dv_model");
		//$this->load->model("guest_comment_model");
		//$this->load->model("news_events_model");
		//$this->load->model("roomcottages_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
	}
	//START ------------------dv---------------------
	function index()
	{
		$data1["list_dvs"] = $this->dv_model->get_all_dv();	
		$this->load->view('dv_list_view',$data1);
	}
	
	function SearchCompany()
	{
		$data1["list_dvs"]=$this->dv_model->getdvSearchBydv_company_name($_POST['search']);
		$this->load->view('dv_list_view',$data1);
	}
	
	function view_dv()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["list_dvs"] = $this->loads_model->getdv_info($code);
		//$data["list_customers"] = $this->customers_model->getcustomers();
		$this->load->view('dv_list_view',$data);
	}
	function search()
	{
		$data['title']="Administrator Page";
		$data["list_dvsearch"] = $this->dv_model->get_all_dvsearch();
	
		$this->load->view('dv_list_view',$data);
	}
	
	function p_getsearchinfo()
	{		
		$info = $this->dv_model->getatSearchBydv_company_name($_GET['dv_company_name']);			
		$this->output->set_content_type('application/json');
    	$this->output->set_output(json_encode($info));
	}
	
	function add_dv()
	{
		//$data["driver_dv_data"] = $this->dv_model->add_view_driver_dv();
		$this->load->view('dv_add_view');
	}
	
	function p_add_dv()
	{
		$this->load->database();			
		$rating =$_POST['rating'];
		$vendor_type =$_POST['vendor_type'];
		$priority_no =$_POST['dv_n_name'];
		$dv_company_name =$_POST['dv_company_name'];
		$dv_n_name =$_POST['dv_n_name'];
		$f_name =$_POST['f_name'];
		$l_name =$_POST['l_name'];
		$address =$_POST['address'];
		$city =$_POST['city'];			
		$state =$_POST['state'];
		$zipcode =$_POST['zipcode'];
		$cell_phone_num =$_POST['cell_phone_num'];
		$fax_num =$_POST['fax_num'];
		$alt_phone_num =$_POST['alt_phone_num'];
		$email_add =$_POST['email_add'];
		$trailer_num =$_POST['trailer_num'];
		$type_of_truck =$_POST['type_of_truck'];
		$hazmat =$_POST['hazmat'];			
		$wearhousing =$_POST['wearhousing'];					
		$truck_num =$_POST['truck_num'];			
		$mc_num =$_POST['mc_num'];
		$dot_no =$_POST['dot_no'];		
		$insurance_name =$_POST['insurance_name'];		
		$i_c_a =$_POST['i_c_a'];				
		$ins_p_no =$_POST['ins_p_no'];						
		$insurance_no =$_POST['insurance_no'];				
		$expr_date =$_POST['expr_date'];								
		$rep =$_POST['rep'];
		$dv_comment_box =$_POST['dv_comment_box'];
		//		$contract_amt =$_POST['txtcontract_amt'];
		$_sql="insert into dv_profile(profile_type,rating,vendor_type,priority_no,dv_company_name,dv_n_name,f_name,l_name,address,city,state,zipcode,cell_phone_num,fax_num,alt_phone_num,email_add,trailer_num,type_of_truck,hazmat,wearhousing,truck_num,mc_num,dot_no,insurance_name,i_c_a,ins_p_no,insurance_no,expr_date,rep,dv_comment_box)";

		$_sql.="values('DV','$rating','$vendor_type','$priority_no','$dv_company_name','$dv_n_name','$f_name','$l_name','$address','$city','$state','$zipcode','$cell_phone_num','$fax_num','$alt_phone_num','$email_add','$trailer_num','$type_of_truck','$hazmat','$wearhousing','$truck_num','$mc_num','$insurance_name','$dot_no','$i_c_a','$ins_p_no','$insurance_no','$expr_date','$rep','$dv_comment_box')";

		$query = $this->db->query($_sql); 
	/*	$dv_id=$this->db->insert_id();
		$_sql="insert into dv_contract(dv_id,contract_amount)";
		$_sql.="values($dv_id,$contract_amt)";
		$query = $this->db->query($_sql); */
		$data["list_dvs"] = $this->dv_model->get_all_dv();	
		$this->load->view('dv_list_view',$data);

	}

	function edit_dv()
	{
 	    $code = $this->uri->segment(3);
		$data["info"] = $this->dv_model->getdv_info($code);	
		$this->load->view('dv_edit_view',$data);
	}

	function p_edit_dv()
	{
		$this->load->database();
		    $driver_code= $_POST['hid_profileid'];
		$rating =$_POST['rating'];
		$vendor_type =$_POST['vendor_type'];
		$priority_no =$_POST['dv_n_name'];
		$dv_company_name =$_POST['dv_company_name'];
		$dv_n_name =$_POST['dv_n_name'];
		$f_name =$_POST['f_name'];
		$l_name =$_POST['l_name'];
		$address =$_POST['address'];
		$city =$_POST['city'];			
		$state =$_POST['state'];
		$zipcode =$_POST['zipcode'];
		$cell_phone_num =$_POST['cell_phone_num'];
		$fax_num =$_POST['fax_num'];
		$alt_phone_num =$_POST['alt_phone_num'];
		$email_add =$_POST['email_add'];
		$trailer_num =$_POST['trailer_num'];
		$type_of_truck =$_POST['type_of_truck'];
		$hazmat =$_POST['hazmat'];			
		$wearhousing =$_POST['wearhousing'];					
		$truck_num =$_POST['truck_num'];			
		$mc_num =$_POST['mc_num'];
		$dot_no =$_POST['dot_no'];		
		$insurance_name =$_POST['insurance_name'];		
		$i_c_a =$_POST['i_c_a'];				
		$ins_p_no =$_POST['ins_p_no'];						
		$insurance_no =$_POST['insurance_no'];				
		$expr_date =$_POST['expr_date'];								
		$rep =$_POST['rep'];
		$dv_comment_box =$_POST['dv_comment_box'];
				//	$dv_comment_box = $_POST['txtdv_comment_box'];
		//	$contract_amt = $_POST['txtcontract_amt'];
			$query = $this->db->query("UPDATE dv_profile SET 
														  	rating='$rating', 
														  	vendor_type='$vendor_type', 
														  	priority_no='$priority_no',
														  	dv_company_name='$dv_company_name', 
														  	dv_n_name='$dv_n_name',
														  	f_name='$f_name',
														  	l_name='$l_name',
														  	address ='$address',
															city ='$city',			
															state ='$state',
															zipcode ='$zipcode',
														  	cell_phone_num='$cell_phone_num',
														  	fax_num='$fax_num',
															alt_phone_num='$alt_phone_num',
														  	email_add='$email_add',
														  	trailer_num='$trailer_num',
														  	type_of_truck='$type_of_truck',	
														  	hazmat='$hazmat',																
														  	wearhousing='$wearhousing',																
														  	truck_num='$truck_num',																													
													  		mc_num='$mc_num',
														  	dot_no='$dot_no',
															insurance_name='$insurance_name',
														  	i_c_a='$i_c_a',		
														  	ins_p_no='$ins_p_no',																														
														  	insurance_no='$insurance_no',		
														  	expr_date='$expr_date',																																
														  	rep='$rep',
															dv_comment_box='$dv_comment_box' where driver_code=$driver_code");
		$data["list_dvs"] = $this->dv_model->get_all_dv();	
		$this->load->view('dv_list_view',$data);		
	}
	function delete_dv()
	{
		$this->load->database();		
		$code = $this->uri->segment(3);
		$query = $this->db->query("delete from dv_profile where driver_code='$code'");
		$data["list_dvs"] = $this->dv_model->get_all_dv();	
		$this->load->view('dv_list_view',$data);
	}
	
/*
function search($search_terms = '', $start = 0)
	{
		// If the form has been submitted, rewrite the URL so that the search
		// terms can be passed as a parameter to the action. Note that there
		// are some issues with certain characters here.
		if ($this->input->post('q'))
		{
			redirect('/dv/search/' . $this->input->post('q'));
		}
		
		if ($search_terms)
		{
			// Determine the number of results to display per page
			$results_per_page = $this->config->item('results_per_page');
			
			// Mark the start of search
			$this->benchmark->mark('search_start');
			
			// Load the model, perform the search and establish the total
			// number of results
			$this->load->model('dv_model');
			$results = $this->dv_model->search($search_terms, $start, $results_per_page);
			$total_results = $this->dv_model->count_search_results($search_terms);
			
			// Mark the end of search
			$this->benchmark->mark('search_end');
			
			// Call a method to setup pagination
			$this->_setup_pagination('/dv/search/' . $search_terms . '/', $total_results, $results_per_page);
			
			// Work out which results are being displayed
			$first_result = $start + 1;
			$last_result = min($start + $results_per_page, $total_results);
		}
		
		// Render the view, passing it the necessary data
		$this->load->view('search_results', array(
			'search_terms' => $search_terms,
			'first_result' => @$first_result,
			'last_result' => @$last_result,
			'total_results' => @$total_results,
			'results' => @$results
		));
		
		// Enable the profiler
		$this->output->enable_profiler(TRUE);
	}
	
	/**
	 * Setup the pagination library.
	 *
	 * @param string $url The base url to use.
	 * @param string $total_results The total number of results.
	 * @param string $results_per_page The number of results per page.
	 * @return void
	 * @author Joe Freeman
	 *//*
	function _setup_pagination($url, $total_results, $results_per_page)
	{
		// Ensure the pagination library is loaded
		$this->load->library('pagination');
		
		// This is messy. I'm not sure why the pagination class can't work
		// this out itself...
		$uri_segment = count(explode('/', $url));
		
		// Initialise the pagination class, passing in some minimum parameters
		$this->pagination->initialize(array(
			'base_url' => site_url($url),
			'uri_segment' => 4,
			'total_rows' => $total_results,
			'per_page' => $results_per_page
		));
	}*/


	function logout()
	{
		//$this->load->library('session');
		//$this->session->sess_destroy();
		session_start();
		session_destroy();
		//echo $_SESSION['Administrator_log'];
		//unset($_SESSION['Administrator_log']);
			//$data["newsresult"] = $this->dv_model->dv_all_driver_dv();
			$this->load->view('admin_view');
	}

}

?>